#include <printk.h>
#include <kernel.h>
#include <assert.h>
#include <interrupt.h>
#include <clock.h>
#include <process.h>
#include <mm.h>

INIT_ASSERT

extern void clock_int(void);
void taskA(void)
{
    int i = 0;
    int j = 0;
    while(1)
    {
        
        if(i++ % 100000 == 0)
            printk("{[A]:%x}",kmalloc(20));
    }
}

void taskB(void)
{
    int i = 0;
    int j = 1000;
    while(1)
    {
        if(i++ % 100000 == 0)
            printk("{[B]: %x}",kmalloc(40));
    }
}
void mem_test(void)
{
    char *mem;
    mem = kmalloc(20);
    printk("mem:%x\n", mem);
    mem = kmalloc(50);
    printk("mem:%x\n", mem);
    free(mem);
    mem = kmalloc(50);
    printk("mem:%x\n", mem);
    free(mem);
    mem = kmalloc(50);
    printk("mem:%x\n", mem);
    free(mem);
    mem = kmalloc(50);
    printk("mem:%x\n", mem);
    free(mem);
}
extern void _Low_ScreenClean(void);
/*
 * moos 主函数
 */
void moos_main(void)
{
    irq_init();
    user_mem_init(DMEM_USER_START, DMEM_USER_END);
    kernel_mem_init(DMEM_KERNEL_START, DMEM_KERNEL_END);

    kmem_mannager_init();
    task_init();
    mem_test();
    clock_init();

    register_task((uint32_t)taskA, DA_DPL1);
    register_task((uint32_t)taskB, DA_DPL1);
    run_task;
}